<?php
namespace Harvey\Toolsbox\traits;
/*
 * 事件处理
 *  Created by Harvey on  2025/8/10
 */
trait Event
{
    private $callbacks = [];

    // 监听事件
    private function on(string $event, callable $callback)
    {
        $this->callbacks[$event] = $callback;
        return $this;
    }

    // 触发事件
    private function trigger(string $event, ...$args)
    {
        if (isset($this->callbacks[$event])) {
            return call_user_func_array($this->callbacks[$event], $args);
        }
        return null;
    }
}